<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="月份">
              <a-month-picker v-model="queryParam.monthParam" placeholder="请选择月份" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-has="'assetLedger:export'" type="primary" icon="download" @click="handleExportXls('资产台账统计')">导出
      </a-button>
    </div>


    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        :scroll="{ x: 2000, y: screenHeight }"
        rowKey="id"
        class="j-table-force-wrap"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">
        <span slot="serial" slot-scope="text,record,index">{{ index + 1 }}</span>
        <template slot="footer" slot-scope="currentPageData">
          <a-table
            bordered
            class="footerTable"
            size="small"
            :columns="footColumns"
            :dataSource="footerData"
            :scroll="{ x: 2000, y: screenHeight }"
            :pagination="false"
            :showHeader="false">
            <span slot="serial">合计</span>
          </a-table>
        </template>
      </a-table>
    </div>

    <assetInfo-modal ref="modalForm" @ok="modalFormOk"></assetInfo-modal>
    <assetInfoDisposal-modal ref="modalDisposalForm" @ok="modalDisposalOk"></assetInfoDisposal-modal>
  </a-card>
</template>

<script>
import { getAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import AssetInfoModal from '../../modules/AssetInfoModal'
import AssetInfoDisposalModal from '../../modules/AssetInfoDisposalModal'
import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import JInput from '@/components/jeecg/JInput'
import JDate from '@/components/jeecg/JDate.vue'
import '@/assets/less/TableExpand.less'

export default {
  name: 'IncomeOperatingStatistical',
  mixins: [JeecgListMixin],
  components: {
    JDate,
    JInput,
    JDictSelectTag,
    AssetInfoDisposalModal,
    AssetInfoModal
  },
  data () {
    return {
      description: '经营收入汇总',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'rowIndex',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          fixed: 'left',
          customRender: (text, record, index) =>
            `${(this.ipagination.current - 1) * this.ipagination.pageSize + index + 1}`
        },
        {
          title: '管理类型',
          align: 'center',
          dataIndex: 'managementType'
        },
        {
          title: '项目',
          align: 'center',
          dataIndex: 'project'
        },
        {
          title: '租金基数',
          align: 'center',
          dataIndex: 'baseRent'
        },
        {
          title: '已换约基数',
          align: 'center',
          dataIndex: 'changeRent'
        },
        {
          title: '本月收入',
          align: 'center',
          children: [
            {
              title: '本月收入',
              align: 'center',
              children: [
                {
                  title: '实收',
                  align: 'center',
                  dataIndex: 'thisMonthPaid'
                },
                {
                  title: '预转',
                  align: 'center',
                  dataIndex: 'thisMonthPrerotation'
                },
                {
                  title: '小计',
                  align: 'center',
                  dataIndex: 'thisMonthtotal'
                },
                {
                  title: '征收率',
                  align: 'center',
                  dataIndex: 'thisMonthRate'
                }
              ]
            },
            {
              title: '本欠收入',
              align: 'center',
              dataIndex: 'thisMonthOwe'
            },
            {
              title: '历欠收入',
              align: 'center',
              dataIndex: 'historyOwe'
            },
            {
              title: '其他收入',
              align: 'center',
              dataIndex: 'other'
            },
            {
              title: '小计',
              align: 'center',
              dataIndex: 'total'
            }
          ]
        },
        {
          title: '本月欠租',
          align: 'center',
          dataIndex: 'thisMonthBatches'
        },
        {
          title: '累计收入',
          align: 'center',
         children: [
           {
             title: '常租收入',
             align: 'center',
             dataIndex: 'longRentIncome'
           },
           {
             title: '本欠收入',
             align: 'center',
             dataIndex: 'lessIncome'
           },{
             title: '历欠收入',
             align: 'center',
             dataIndex: 'historyIncome'
           },{
             title: '其他收入',
             align: 'center',
             dataIndex: 'otherIncome'
           },{
             title: '小计',
             align: 'center',
             dataIndex: 'totalIncome'
           }
         ]
        },
        {
          title: '累计欠租余额',
          align: 'center',
          dataIndex: 'cumulativeBatches'
        },
        {
          title: '预收结存',
          align: 'center',
          dataIndex: 'balanceAdvance'
        },
        {
          title: '管理公司',
          align: 'center',
          dataIndex: 'companyId_dictText'
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark'
        }
      ],
      footColumns: [],
      footerData: [{
        key: '1'
      }],
      url: {
        list: '/zcgl/statisticalReport/incomeOperatingStatistical',
        // exportXlsUrl: '/zcgl/statisticalReport/assetsParameter/exportXls'
      },
      dictOptions: {}
    }
  },
  created () {
    this.footColumns.push({
      title: '序号',
      dataIndex: 'rowIndex',
      key: 'rowIndex',
      width: 60,
      align: 'center',
      fixed: 'left',
      customRender: (text, record, index) =>
        '合计'
    })
    this.columns.forEach(value => {
      if (value.title !== '序号') {
        this.footColumns.push(value)
      }
    })
  },
  mounted () {
    const dom = this.$refs.table.$el.querySelectorAll('.ant-table-body')[0]
    dom.addEventListener('scroll', () => {
      this.$refs.table.$el.querySelectorAll('.ant-table-body')[1].scrollLeft = dom.scrollLeft
    }, true)
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    importXlsDictUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importXlsDictUrl}`
    }
  },
  methods: {
    loadData (arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams()//查询条件
      this.loading = true
      getAction(this.url.list, params).then((res) => {
        console.log(this.url.list + ':')
        console.log(res)
        if (res.success) {
          this.dataSource = res.result.records
          this.ipagination.total = res.result.total

          let rentPrice = 0
          let monthlyRent = 0
          let cashDeposit = 0
          let worth = 0
          res.result.records.forEach(value => {
            rentPrice += value.rentPrice
            monthlyRent += value.monthlyRent
            cashDeposit += value.cashDeposit
            worth += value.worth
          })
          this.footerData[0].rentPrice = rentPrice
          this.footerData[0].monthlyRent = monthlyRent
          this.footerData[0].cashDeposit = cashDeposit
          this.footerData[0].worth = worth
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    initDictConfig () {
      this.addColumns()
    },
    modalDisposalOk () {
      this.loadData()
    }

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
<style>
.ant-table-footer {
  padding: 0;
}

.footerTable .ant-table-body {
  margin: 0px !important;
}

.footerTable .ant-table-thead {
  display: none;
}

.ant-table-footer .ant-table-body {
  overflow-x: hidden !important;
}

.footerTable .ant-table-small .ant-table-bordered {
  border: 0px;
}

.footerTable .ant-table-small .ant-table-bordered .ant-table-footer {
  border: 0px;
}
</style>